package com.aviation.sell_ticket.mapper;

import com.aviation.sell_ticket.pojo.Aviation_order_details;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface OrderDetailsMapper {

    @Select("SELECT a.seat_id FROM aviation_order_details AS a,aviation_order AS b WHERE a.flight_id=#{flightId} and a.departure_date=#{departureDate} and a.order_id=b.order_id and b.payment in (0,2)")
    public List<String> queryOrderDetails(@Param("flightId")String flightId, @Param("departureDate")LocalDate departureDate);

    @Insert("insert into aviation_order_details values(#{details.details_id},#{details.passenger_name},#{details.passenger_number},#{details.passenger_phone},#{details.departure_date},#{details.seat_id},#{details.model_id},#{details.order_id},#{details.flight_id})")
    public Integer InsertOrderDetails(@Param("details")Aviation_order_details details);

    @Select("select passenger_name,passenger_number,passenger_phone,departure_date,seat_id,flight_id from aviation_order_details where order_id=#{orderId}")
    public List<Aviation_order_details> detailedOrder(@Param("orderId")String orderId);

    @Select("SELECT a.* FROM aviation_order_details AS a,aviation_order AS b WHERE a.passenger_name=#{passengerName} and a.passenger_number=#{passengerNumber} and a.flight_id=#{flightId} and a.departure_date=#{departureDate} and b.order_id=a.order_id and b.payment in (0,2)")
    public Aviation_order_details sameOrder(@Param("passengerName") String passengerName, @Param("passengerNumber")String passengerNumber, @Param("flightId")String flightId, @Param("departureDate")LocalDate departureDate);

}
